local zhenwei = fk.CreateSkill{
    name = "wk_heg__zhenwei",
    tags = { Skill.Limited },
}

Fk:loadTranslationTable{
    ["wk_heg__zhenwei"] = "镇卫",
    [":wk_heg__zhenwei"] = "限定技，其他角色的出牌阶段开始时，你可调离至多两名你与其外的角色，且此回合结束时，若你于此回合内未受到过伤害，你复原此技能。",

    ["#wk_heg__zhenwei-choose"] = "镇卫：你可以调离至多两名你与当前回合外的角色",
    ["#Heg_zhenwei-Reset"] = "%from 重置了限定技 “%arg”",

    ["$wk_heg__zhenwei1"] = "再敢来犯，定叫你无功而返！",
    ["$wk_heg__zhenwei2"] = "江夏防线，固若金汤。",
}

local H = require "packages/ol_hegemony/util"

zhenwei:addEffect(fk.EventPhaseStart,{
  anim_type = "big",
  can_trigger = function (self, event, target, player, data)
      return player:hasSkill(zhenwei.name) and player:usedSkillTimes(zhenwei.name, Player.HistoryGame) == 0 and target ~= player and target.phase == Player.Play
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player), function(p) return p ~= room.current and p:getMark("@@lure_tiger-turn") == 0 end)
    local tos = room:askToChoosePlayers(player,{
        targets = targets,
        min_num = 1,
        max_num = 2,
        prompt = "#wk_heg__zhenwei-choose",
        skill_name = zhenwei.name,
        cancelable = false,
    })
    -- room:useVirtualCard("lure_tiger", nil, player, tos, zhenwei.name)
    for _, p in ipairs(tos) do
      room:setPlayerMark(p, "@@lure_tiger-turn", 1)
      room:setPlayerMark(p, MarkEnum.PlayerRemoved .. "-turn", 1)
      room.logic:trigger(H.PlayerRemoved, p, {who = p}) -- FIXME
    end
  end,
})

zhenwei:addEffect(fk.TurnEnd,{
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:usedSkillTimes(zhenwei.name, Player.HistoryTurn) == 0 then return false end
    local targets = {}
    player.room.logic:getActualDamageEvents(1, function(e)
      local damage = e.data
      if player == damage.to then
        table.insertIfNeed(targets, damage.to)
      end
      return false
    end)
    return #targets == 0
  end,
  on_use = function(self, event, target, player, data)
      player:setSkillUseHistory("wk_heg__zhenwei", 0, Player.HistoryGame)
      player.room:sendLog{
      type = "#Heg_zhenwei-Reset",
      from = player.id,
      arg = zhenwei.name,
      toast = true,
    }
  end,
})



return zhenwei